package com.zeng.nicecore.convert;


import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public interface AbstractConvertor<B,V> {

    V beanToVo(B b);

    B voToBean(V v);

    default List<V> toList(List<B> list) {
        if (list == null) {
            list = Collections.emptyList();
        }
        ArrayList<V> vs = new ArrayList<>(list.size());

        for (B b : list) {
            V v = beanToVo(b);
            vs.add(v);
        }
        return vs;
    }
    default List<B> toBeanList(List<V> list) {
        if (list == null) {
            list = Collections.emptyList();
        }
        ArrayList<B> bs = new ArrayList<>(list.size());

        for (V v : list) {
            B b = voToBean(v);
            bs.add(b);
        }
        return bs;
    }
}
